/**
 * @author zhangqiang
 * @date   17/7/20
 */
import React, {Component} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators } from 'redux'
import authService from  '../../services/authService';
import {getHandleList} from '../../actions/handleListActions'; //立即办理列表页
import UrlOperation from '../../utils/urlOperation'  //获取url参数
import {Toast} from 'antd-mobile'
import '../../../styles/payment.scss';
import common from '../../utils/common'
import style from './index.scss'

class JumpUrl extends Component {
	constructor(props) {
		super(props);
		this.state={}
			// this.openId = UrlOperation.getParameters().openId;
			// this.pnUserId = UrlOperation.getParameters().pnUserId;
			// this.timestamp = UrlOperation.getParameters().timestamp;
			// this.sign = UrlOperation.getParameters().sign;
	}

	toUrl(url) {
		this.context.router.push(url);
	}

	componentWillMount(){
		this.props.dispatch(getHandleList({networkError: true},(data)=>{
			// let href = window.location.href.split('?')[0].replace('#/JumpUrl', '');
			if(data.length){
				//window.location.replace(`${href}#/handleList`);
				this.props.router.replace('handleList');
				
				// window.location.replace(`${href}?openId=${this.openId}&pnUserId=${this.pnUserId}&timestamp=${this.timestamp}&sign=${this.sign}#/home`);
				// this.toUrl('handleList')
			}else {
				this.props.router.replace('home');
				 //window.location.replace(`${href}#/home`);
				// this.toUrl('home')
			}
		}))


		/*

		let now = new Date();
		let days = now.getTime()/1000;  //时间戳

		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		let postData={
			openId: this.openId,  ///用户id
			pnUserId: this.pnUserId, //合作商ID
			timestamp: this.timestamp,  //时间戳(秒)
			sign: this.sign  //加密串md5（openId=<>&pnUserId=<>×tamp=<>&key=<>）
		}
		authService.auth(postData).then(resultData => {
			Toast.hide();
			if (resultData.code == 1000) {
				let href = window.location.href.split('?')[0].replace('#/', '');
				// window.location.replace(`${href}#/home`);
				// window.location.replace(`${href}#/home/?OutTradeNo=${2222}`);

				this.props.dispatch(getHandleList({},(data)=>{
					if(data.length){
						// window.location.replace(`${href}#/handleList`);
					  //	window.location.replace(`${href}?openId=${this.openId}&pnUserId=${this.pnUserId}&timestamp=${this.timestamp}&sign=${this.sign}#/home`);
						 this.toUrl('handleList')
					}else {
						// window.location.replace(`${href}#/home`);
						this.toUrl('home')
					}
				}))

			}else if(resultData.code == 4444){
				Toast.info(resultData.msg,1)
			} else if(resultData.code == 4006||resultData.code == 4003){
				//请求入口做了从新授权的操作
				// let reload=0;
				// if(reload==0){
				// 	++reload
				// 	window.location.reload()
				// }

			}else {
				Toast.info(resultData.msg, 1)
			}
		})
		*/
	}

	componentDidMount() {
		common.setViewTitle(' ');
	}

	render() {
		return (
			<div></div>
		)
	}
}

//使用context
JumpUrl.contextTypes = {
    router: React.PropTypes.object.isRequired
};

export default connect()(JumpUrl);
